home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / ASSOC.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  929b  |  43 lines

  1. /* Assoc.c -- implementation of key-value association
  2.  
  3. Function:
  4.  
  5. Objects of class Assoc associate a key object with a value object.  They
  6. are used to implement Dictionaries, which are Sets of Associations.
  7.  
  8. */
  9.  
  10. #include "assoc.h"
  11.  
  12. #define THIS    Assoc
  13. #define BASE    LookupKey
  14. // DEFINE_CLASS(THIS,BASE);
  15. DEFINE_CLASS(Assoc, LookupKey);
  16.  
  17. Assoc::Assoc(const Object& newKey, const Object& newValue)
  18. : LookupKey(newKey)
  19. {
  20.     avalue = (Object*)&newValue;
  21. }
  22.  
  23. Object* Assoc::value()  const { return avalue; }
  24.  
  25. Object* Assoc::value(const Object& newvalue)
  26. {
  27.     Object* temp = avalue;
  28.     avalue = (Object*)&newvalue;
  29.     return temp;
  30. }
  31.  
  32. void Assoc::deepenShallowCopy()
  33. {
  34.     BASE::deepenShallowCopy();
  35.     avalue = avalue->deepCopy();
  36. }
  37.  
  38. void Assoc::printOn(ostream& strm) const
  39. {
  40.     strm << className() << "("; BASE::printOn(strm);
  41.     strm << "="; avalue->printOn(strm); strm << ")";
  42. }
  43.